import ReactCropperRef from "@/platform/types/use-bombined-refs-type";
import React, { useRef } from "react";
import { ReactCropperElement } from "react-cropper";

const useCombinedRefs = (...refs: ReactCropperRef[]): React.RefObject<ReactCropperElement> => {
    const targetRef = useRef<ReactCropperElement>(null);

    React.useEffect(() => {
        refs.forEach((ref) => {
            if (!ref) return;

            if (typeof ref === 'function') {
                ref(targetRef.current);
            } else {
                ref.current = targetRef.current;
            }
        });
    }, [refs]);

    return targetRef;
};

export default useCombinedRefs;
